using System;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMSortProperty objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMSortProperty.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMSortProperty
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            TestUtilsDomain.SetupFixture();

            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            _ignoreList.Add("Test_ReadWriteRules", "Reason for ignoring it");
            _ignoreList.Add("Test_LoadThroughSingleRelationship_DMSortOrder", "Reason for ignoring it");
            _ignoreList.Add("Test_SingleRelationshipDeletion_DoNothing_DMSortOrder", "Reason for ignoring it");
        }

        [SetUp]
        public void Setup()
        {
            TestUtilsDomain.SetupTest();
        }
        
        [Test]
        public void Test_ToString_WhenSortDirectionDesc_ShouldSuffixSortDirection()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMSortProperty dMSortProperty = TestUtilsDMSortProperty.CreateUnsavedValidDMSortProperty();
            dMSortProperty.SortDirection = "DESC";
            //---------------Assert Precondition----------------
            Assert.AreEqual("DESC", dMSortProperty.SortDirection);
            //---------------Execute Test ----------------------
            string toStringValue = dMSortProperty.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dMSortProperty.PropertyName + " " + dMSortProperty.SortDirection, toStringValue);
        }
        
        [Test]
        public void Test_ToString_WhenSortDirectionAsc_ShouldNotSuffixSortDirection()
        {
            //---------------Set up test pack-------------------
            BORegistry.DataAccessor = new DataAccessorInMemory();
            DMSortProperty dMSortProperty = TestUtilsDMSortProperty.CreateUnsavedValidDMSortProperty();
            dMSortProperty.SortDirection = "ASC";
            //---------------Assert Precondition----------------
            Assert.AreEqual("ASC", dMSortProperty.SortDirection);
            //---------------Execute Test ----------------------
            string toStringValue = dMSortProperty.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dMSortProperty.PropertyName, toStringValue);
        }

        [Test]
        public void Test_NewSortProperty_ShouldHaveCorrectSortPositionValue()
        {
            //---------------Set up test pack-------------------
            DMSortOrder sortOrder = TestUtilsDMSortOrder.CreateUnsavedValidDMSortOrder();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, sortOrder.DMSortProperties.Count);
            //---------------Execute Test ----------------------
            DMSortProperty dmSortProperty = sortOrder.DMSortProperties.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(1, sortOrder.DMSortProperties.Count);
            Assert.AreEqual(1, dmSortProperty.SortPosition);
        }

        [Test]
        public void Test_NewSortProperty_ShouldHaveCorrectSortPositionValue_HasExistingSortProperties()
        {
            //---------------Set up test pack-------------------
            DMSortProperty dmSortProperty1 = TestUtilsDMSortProperty.CreateUnsavedValidDMSortProperty();
            dmSortProperty1.SortPosition = 24;
            DMSortOrder dmSortOrder = dmSortProperty1.DMSortOrder;
            DMSortProperty dmSortProperty2 = dmSortOrder.DMSortProperties.CreateBusinessObject();
            dmSortProperty2.SortPosition = 9;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmSortOrder.DMSortProperties.Count);
            //---------------Execute Test ----------------------
            DMSortProperty newSortProperty = dmSortOrder.DMSortProperties.CreateBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(3, dmSortOrder.DMSortProperties.Count);
            Assert.AreEqual(25, newSortProperty.SortPosition);
        }

        [Test]
        public void Test_SortOrderPropertyName()
        {
            //---------------Set up test pack-------------------
            DMSortProperty dmSortProperty = new DMSortProperty();
            string sortOrderPropertyName = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            dmSortProperty.SortOrderPropertyName = sortOrderPropertyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(sortOrderPropertyName, dmSortProperty.SortOrderPropertyName);
        }
    }
}